


<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="20">
        <el-form :inline="true" class="demo-form-inline">
          <!-- <el-form-item>
            <el-input v-model="id" placeholder="编码"></el-input>
          </el-form-item> -->

          <el-form-item>
            <el-input v-model="name" placeholder="角色名称"></el-input>
          </el-form-item>

          <el-date-picker
            v-model="value1"
            type="datetime"
            placeholder="选择开始日期时间"
          >
          </el-date-picker>

          <el-date-picker
            v-model="value2"
            type="datetime"
            placeholder="选择结束日期时间"
          >
          </el-date-picker>

          <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-container>
      <el-button
        class="el-icon-circle-plus"
        size="mini"
        type="primary"
        @click="addEmp()"
        >添加</el-button
      >
    </el-container>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="systemRolesId" label="编号" width="180">
      </el-table-column>

      <!-- <el-table-column prop="rolesCode" label="角色编码" width="180">
      </el-table-column> -->

      <el-table-column prop="rolesName" label="角色名称" width="180">
      </el-table-column>

      <el-table-column prop="rolesDescn" label="角色描述" width="180">
      </el-table-column>

      <el-table-column
        prop="rolesCretime"
        label="创建时间"
        sortable
        width="180"
      >
      </el-table-column>

      <el-table-column
        prop="rolesStatus"
        label="状态"
        width="100"
        :filters="[
          { text: '启用', value: '0' },

          { text: '禁用', value: '1' },
        ]"
        :filter-method="filterTag"
        filter-placement="bottom-end"
      >
        <template slot-scope="scope">
          <el-tag disable-transitions>
            <span v-if="scope.row.rolesStatus == 1">禁用</span
            ><span v-if="scope.row.rolesStatus == 0">启用</span>
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >

          <el-dropdown style="left: 30px">
            <span class="el-dropdown-link">
              更多<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleDelete(scope.row)"
                >删除</el-dropdown-item
              >
              <el-dropdown-item @click.native="accredit(scope.row)"
                >授权</el-dropdown-item
              >
              <el-dropdown-item @click.native="dispose(scope.row)"
                >配置</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[2, 4, 6]"
      :page-size="4"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

    <el-dialog title="提示" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <!-- <el-form-item label="编码" :label-width="formLabelWidth">
          <el-input v-model="form.rolesCode" autocomplete="off"></el-input>
        </el-form-item> -->

        <el-form-item label="角色名称" :label-width="formLabelWidth">
          <el-input v-model="form.rolesName" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="角色名称" :label-width="formLabelWidth">
          <el-select v-model="form.rolesStatus">
            <el-option value="0" label="启用"></el-option>
            <el-option value="1" label="禁用"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="角色描述" :label-width="formLabelWidth">
          <el-input v-model="form.rolesDescn" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateAndAdd()">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="授权"
      :visible.sync="dialogFormVisible1"
      @close="closeDialog1"
    >
      <template>
        <template>
          <el-transfer
            style="text-align: left; display: inline-block"
            v-model="yesData"
            :props="{ key: 'systemUserId', label: 'usersUsername' }"
            :titles="['全部用户', '已选用户']"
            @change="handleChange"
            :data="fileArr"
          
          ></el-transfer>
        </template>
      </template>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="authorization()">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      @close="closeDialog"
      title="标题XX"
      :visible.sync="dialogFormVisible2"
      width="75%"
      top="0vh"
      custom-class="center-dialog"
    >
      <div style="height: 65vh">
        <el-col :span="8">
          <el-card
            shadow="always"
            class="bb"
            v-infinite-scroll="load"
            style="overflow: auto"
          >
            <el-tabs type="border-card">
              <el-tab-pane label="菜单列表"> </el-tab-pane>

              <el-tree
                default-expand-all
                node-key="menuId"
                :default-checked-keys="menuIdcaidan"
                show-checkbox
                :check-strictly="true"
                :default-expanded-all="false"
                class="filter-tree"
                :data="data"
                :props="defaultProps"
                ref="tree1"
                @node-click="clickTree"
                 @check="checkBoxFn"
              >
              </el-tree>
              <!--     @node-click="clickTree"
              @check="checkBoxFn" -->
            </el-tabs>
          </el-card>
        </el-col>

        <el-col :span="8">
          <el-card shadow="always" class="cc">
            <el-tabs type="border-card">
              <el-tab-pane label="提示">
                <el-table :data="tableData1"  ref="multipleTable" stripe style="width: 100%" @selection-change="handleSelectionChange">
                  <el-table-column type="selection" width="55">
                  </el-table-column>
                  <el-table-column
                    prop="systemPermissionId"
                    label="编号"
                    width="180"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="permissionName"
                    label="权限名称"
                    width="180"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="permissionCode"
                    label="权限编码"
                    width="180"
                  >
                  </el-table-column>
                </el-table>

             
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>
      </div>

      <span slot="footer">
        <el-button @click="dialogFormVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="disposeAdd([tableData1[1], tableData1[2]])">确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

 



  

<script>
import axios from "axios";

import moment from "moment";
export default {
  data() {
    return {
      multipleSelection: [],
      defaultProps: {
        children: "children",

        label: "menuName",
      },
      menuIdcaidan: [],
      data: [],
      yesData: "",
      fileArr: [], //穿梭框文件列表
      fileIdArr: [], //穿梭框文件id数组
      yesData: [], // 注意:key 的字符类型要一致!!!
      value: [],
      dialogTableVisible: false,
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      form: {},
      formLabelWidth: "120px",
      tableData: [],
      tableData1:[],
      currentPage4: 1, //当前页
      num: 4, //每页条数
      total: 0,
      numshu: 1,
      bj: "",
      id: "",
      did: "",
      name: "",
      value1: "",
      value2: "",
      count: 0,
      bj1:"",
      systemRolesId:"",
      dialogFormVisible: false,
      formLabelWidth: "120px",
      caidanbh:"",
      caidanRole:"",
      datadd:[],
      systemPermissionId1:"",
      SsystemPermissionId:"",
    };
  },
  methods: {

      checkBoxFn(){


        let checkdata = this.$refs.tree1.getCheckedNodes();
       


            var ss = ""
          for(var i=0;i<checkdata.length;i++){


            ss += checkdata[i].menuId+","
            // arr.push(checkdata[i].cliqueId)
          }
          this.caidanbh= ss

     

      },
    handleSelectionChange(val) {

    //  systemPermissionId  
    // console.log(this.multipleSelection)
    
        this.multipleSelection = val;

    var ss = ""

    for (let index = 0; index < this.multipleSelection.length; index++) {
      const element = this.multipleSelection[index];
              ss +=element.systemPermissionId+","
    }

    this.SsystemPermissionId = ss;
    
},
    disposeAdd(){

     

       

              console.log(this.SsystemPermissionId)

               console.log(this.caidanRole)

              axios.get("/api/SystemTmsMenuRoleinsert",{ params: { name: this.caidanRole,"user":this.caidanbh } }).then((data) => {

                 
                      axios.get("/api/SystemTmsRolePermissioninsert",{ params: { name: this.caidanRole,"user":this.SsystemPermissionId } }).then((data) => {

                               this.getEmpList()
                           
                       })
                this.dialogFormVisible2 = false;
              })
         
        
    },
    clickTree(v, e) {

  console.log(this.tableData1)


     
axios
        .get("/api/SystemTmsMenspermission", {
          params: {
            name: v.menuName,
          },
        })
        .then((aa) => {
        
          console.log(aa.data);
      
          this.tableData1 = aa.data; //获取分页数据
     
      
  
        });
   
     
    },

    closeDialog1() {},
    closeDialog() {
      this.menuIdcaidan = [];
    },
    load() {
      this.count += 2;
    },
    dispose(row) {
    this.caidanRole =   row.systemRolesId

      axios
        .get("/api/SystemMenusAllByList", { params: { name: row.rolesName } })
        .then((data) => {
          this.data = data.data;
        });

      axios
        .get("/api/SystemMenusByNameAllByList", {
          params: { name: row.rolesName },
        })
        .then((data) => {
          var menuId1 = data.data;

          var ss = [];
          for (let index = 0; index < menuId1.length; index++) {
            const element = menuId1[index];
            ss.push(element.menuId);
            console.log(element.menuId);
          } 

          

          this.menuIdcaidan = ss;
        });


       axios
        .get("/api/SystemTmsMenspermissionByqx", { params: { name: row.rolesName } })
        .then((data) => {
          this.datadd =   data.data
        });

      this.dialogFormVisible2 = true;
    },

    handleChange(value, direction, movedKeys) {
      console.log( movedKeys);

  console.log(value)
    console.log(direction)

  if(direction=="right"){
  this.bj1="true"
  }else if(direction=="left"){
      this.bj1="false"
  }

      this.fileIdArr = movedKeys; //文件列表的id数组
    },
    authorization() {
      console.log(this.systemRolesId)

  var ids = "";
   


 
      for (let index = 0; index < this.fileIdArr.length; index++) {
        
              ids +=  this.fileIdArr[index] + ",";
      }

      if(this.bj1=="true"){
          axios.get("/api/UpdateSystemUserRole1",{ params: { name: this.systemRolesId,"user":ids } }).then((data) => {
              this.getEmpList()
          this.dialogFormVisible1 = false;
      });
      }else if(this.bj1=="false"){
          axios.get("/api/SystemTmsUserRoleDEl",{ params: {"user":ids } }).then((data) => {
              this.getEmpList()
          this.dialogFormVisible1 = false;
      });
      }

    

   
      
    },

    accredit(row) {
      this.systemRolesId = row.systemRolesId
      axios.get("/api/XSgUsersAllList").then((data) => {
        console.log(data.data);
        this.fileArr = data.data;
      });

      axios
        .get("/api/SystemXsgAllLIst", { params: { name: row.rolesName } })
        .then((data) => {
          var sk1 = [];
          var ss = data.data;
          //  this.fileArr  = data.data;
          for (let index = 0; index < ss.length; index++) {
            const element = ss[index];
            var kk = element.systemTmsUsers.systemUserId;
            sk1.push(kk);
          }

          this.yesData = sk1;
        });

      this.dialogFormVisible1 = true;
    },

    filterTag(value, row) {
      return row.rolesStatus === value;
    },

    handleDelete(row) {
      //建议使用静态删除 data.splice(index,1)

      this.$confirm("确定删除此员工吗?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          axios
            .get("/api/SystemTmsRolesXSGdel", {
              params: { id: row.systemRolesId },
            })
            .then((data) => {
              alert("删除成功");
              this.getEmpList();
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    updateAndAdd() {
      if (this.bj == "true") {
        console.log(this.form);
        axios
          .post("/api/SystemTmsRolesXSGupdate", {
            SystemTmsRoles: this.form,
          })
          .then((data) => {
            alert("修改成功");
            this.getEmpList();
            this.dialogFormVisible = false;
          });
      } else {
        console.log(this.form);
        axios
          .get("/api/SystemTmsRolesXSGadd", {
            params: { record: JSON.stringify(this.form) },
          })
          .then((data) => {
            alert("添加成功");
            this.getEmpList();
            this.dialogFormVisible = false;
          });
      }
    },

    addEmp() {
      this.dialogFormVisible = true;
      this.form = {};
      this.bj = "false";
    },

    handleEdit(index, row) {
      this.form = row;
      this.bj = "true";
      this.dialogFormVisible = true;
    },

    onSubmit() {
      this.getEmpList();
    },
    getEmpList() {
      axios
        .get("/api/SystemTmsRolesAllList", {
          params: {
            page: this.currentPage4,
            num: this.num,
            name: this.name,
            id: this.id,
            datetimes: this.value1,
            datetimes1: this.value2,
          },
        })
        .then((data) => {
          this.tableData = data.data.rows; //获取分页数据
          this.total = data.data.total; //获取总记录数
        });
    },

    handleSizeChange(val) {
      console.log("数据" + val);
      this.num = val;

      this.getEmpList();
    },
    handleCurrentChange(val) {
      console.log("当前页" + val);
      this.currentPage4 = val;
      this.getEmpList();
    },
  },
  created() {
    this.getEmpList();
  },
};
</script>


<style>
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}

.cc {
  width: 800px;

  height: 700px;
}

.el-dropdown {
  vertical-align: top;
}

.el-dropdown + .el-dropdown {
  margin-left: 15px;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.aa {
  background: #f0f9eb;
}

.bb {
  width: 400px;

  height: 700px;
}
.center-dialog {
  top: 50%;
  transform: translateY(-50%);
}

.dd {
  height: 730px;
}
</style>

